import Vue from "vue";
import VueRouter from "vue-router";
import Home from "../views/Home.vue";
import store from "../store/index.js";

Vue.use(VueRouter);

const routes = [
  {
    path: "/index",
    name: "index",
    component: () => import("../views/Index.vue"),
    children: [
      {
        path: "/home",
        name: "home",
        component: () => import("../views/Home.vue"),
      },
      {
        path: "/list",
        name: "list",
        component: () => import("../views/List.vue"),
      },
    ],
  },
  {
    path: "/shopcar",
    name: "shopcar",
    component: () => import("../views/Shopcar.vue"),
  },
  {
    path: "/my",
    name: "my",
    component: () => import("../views/My.vue"),
  },
  {
    path: "/login",
    name: "login",
    component: () => import("../views/Login.vue"),
  },
];

const router = new VueRouter({
  routes,
});

// router.beforeEach((to, from, next) => {
//   if (store.state.user != "") {
//     next();
//   } else {
//     // next("/login");
//     if (to.path == "/login") {
//       next();
//     } else {
//       next("/login");
//     }
//     //因为login页面也会被拦截 有一个死循环 所以需要判断一下
//   }
// });
//全局守卫  注意

export default router;
